package org.jash.shop2201.net

import org.jash.shop2201.entity.BannerEntity
import org.jash.shop2201.entity.CartItem
import org.jash.shop2201.entity.Category
import org.jash.shop2201.entity.Goods
import org.jash.shop2201.entity.Res
import org.jash.shop2201.entity.User
import org.jash.shop2201.mvvm.BaseViewModel
import org.jash.shop2201.utils.service
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Query

interface APIService {
    //挂起方法
    @GET("/goods/info")
    suspend fun getGoods(
        @Query("category_id") category_id: Int,
        @Query("currentPage") currentPage: Int,
        @Query("pageSize") pageSize: Int
    ): Res<List<Goods>>

    @GET("/banner/json")
    suspend fun getBanner(): Res<List<BannerEntity>>

    @POST("/user/loginjson")
    suspend fun login(@Body user: Map<String, String>): Res<User>
    @GET("/goods/detail")
    suspend fun getDetail(@Query("goods_id") goodsId:Int): Res<Goods>
    @POST("/goods/addCar")
    suspend fun addCart(@Body cart:Map<String, String>): Res<Any?>
    @GET("/goods/category")
    suspend fun getCategory():Res<List<Category>>
    @GET("/goods/selectCar")
    suspend fun getCarts():Res<List<CartItem>>
    @POST("/goods/deleteCar")
    suspend fun deleteCart(@Body map:Map<String, String>):Res<Any?>
}
val BaseViewModel.service:APIService by lazy { service() }